package train.DAY625;

import java.io.*;

public class Test625 {
    public static void main(String[] args) throws Exception {
//       byte b[] ={'a','b',127,5};
//        FileOutputStream stream = new FileOutputStream("test.txt");
//        for (int i = 0; i < b.length; i++) {
//                stream.write(b[i]);
//        }
//        stream.close();
//        FileInputStream inputStream = new FileInputStream("test.txt");
//        for (int i = 0; i < inputStream.available(); i++) {
//            System.out.print(inputStream.read()+" ");
//        }

        //序列化，反序列化
//        ObjectOutputStream play = new ObjectOutputStream(new FileOutputStream("play.txt"));
//        persion a = new persion("孙悟空", 500,"123456");
//        play.writeObject(a);
//
//        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("play.txt"));
//        persion o = (persion) objectInputStream.readObject();
//        System.out.println(o.getAge()+o.getName()+o.getPassword());

        showDirs("D:\\Download\\1\\kuang_simple_bbs", " ");
    }
    //读取文件夹内容
    public static void showDirs(String dirname,String space){

        File f1 = new File(dirname);

        if (f1.isDirectory()) {
            System.out.println(space+"目录 " + dirname+"内部：");
            String s[] = f1.list();
            for (int i = 0; i < s.length; i++) {
                File f = new File(dirname + "/" + s[i]);
                if (f.isFile()) {
                    System.out.println(space+"  "+s[i] + " 是一个文件");
                }
            }

            for (int i = 0; i < s.length; i++) {
                File f = new File(dirname + "/" + s[i]);
                if (f.isDirectory()) {
                    showDirs(dirname + "/" + s[i],space+"  "); //递归调用当前方法 实现无穷极显示文件夹内容
                }
            }
        } else {
            System.out.println(dirname + " 不是一个目录");
        }
    }
}
class persion implements Serializable{
    private static final long serialVersionUID = 239472323423479424L;
    private String name;
    private Integer age;
    private transient String password;

    public persion(String name, Integer age, String s) {
        this.name = name;
        this.age = age;
        this.password=s;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}